package org.gitman.agentplatform.ui.summary;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;

import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.table.TableColumnModel;

import org.gitman.agentplatform.ui.MainFrame;
import org.gitman.agentplatform.ui.actions.ActionsManager;
import org.gitman.agentplatform.ui.utils.ColorRenderer;

public class AgentSummaryDetailsPanel extends JPanel{
	private AgentSummaryTabelModel model;
	private AgentSummaryTable table;	
	
	public AgentSummaryDetailsPanel(MainFrame mainFrame){
		ActionsManager actionsManager = mainFrame.getActionsManager();
		
		setLayout(new BorderLayout());
		
		JPanel optionsPanel = new JPanel(new BorderLayout());
		JPanel buttonPanel = new JPanel(new GridLayout(1,3));		
		buttonPanel.add(new JButton(actionsManager.hideAgentsDetailsAction));
		buttonPanel.add(new JButton(actionsManager.updateTableAction));
		buttonPanel.add(new JButton(actionsManager.export2csvDetailsAction));
		optionsPanel.add(buttonPanel, BorderLayout.WEST);
		add(optionsPanel, BorderLayout.NORTH);
		
		model = new AgentSummaryTabelModel();
		table = new AgentSummaryTable(model);		
		JScrollPane scrollPane = new JScrollPane(table);
		add(scrollPane, BorderLayout.CENTER);
		ColorRenderer colorRenderer = new ColorRenderer();
		table.setDefaultRenderer(Color.class, colorRenderer);
		
		TableColumnModel cm = table.getColumnModel();
		int [] widths = model.getWidths();
		for(int i=0;i<widths.length;i++){		
			cm.getColumn(i).setPreferredWidth(widths[i]);
		}
	}
	public void updateTable() {
		model.fireTableDataChanged();
	}
}
